package com.example.wangning.mycarofcountry.recommend.newest;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.android.volley.toolbox.ImageLoader;
import com.example.wangning.mycarofcountry.R;
import com.example.wangning.mycarofcountry.cache.VolleySingleton;

/**
 * Created by dllo on 16/1/7.
 */
public class FocusimgFragment extends Fragment {
    private ImageView adIv;//广告图片
    private String imgurl;// 图片地址
    private VolleySingleton queue;// 定义请求队列
    //单例模式 整个应用中保证只有一个实例对象 且必须是通过静态方法获取
    private static FocusimgFragment focusimgFragment;
    private ImageLoader imageLoader;

    public FocusimgFragment() {


    }

    public static FocusimgFragment getInstance(String imgurl) {
        FocusimgFragment focusimgFragment = new FocusimgFragment();
        //参数传递
        Bundle args = new Bundle();
        args.putString("imgUrl", imgurl);
        focusimgFragment.setArguments(args);
        return focusimgFragment;
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        //初始化请求队列
        queue = VolleySingleton.getVolleyIntance();
        imageLoader = queue.getImageLoader();
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //获得参数
        Bundle bundle = getArguments();
        if (bundle != null) {
            imgurl = bundle.getString("imgUrl");
        }
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        //加载布局
        View view = inflater.inflate(R.layout.fragment_focusing, container, false);
        adIv = (ImageView) view.findViewById(R.id.adIv);
        //拉取网络图片
        queue.getBigBitmap(queue,imgurl,adIv);
        return view;
    }


}
